from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-21 14:34:29.096778
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 21, Jan, 2021
Time: 14:34:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.3815
Nobs: 178.000 HQIC: -46.3378
Log likelihood: 1998.99 FPE: 3.91619e-21
AIC: -46.9902 Det(Omega_mle): 2.39455e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437757 0.144326 3.033 0.002
L1.Burgenland 0.132943 0.075945 1.751 0.080
L1.Kärnten -0.233539 0.061668 -3.787 0.000
L1.Niederösterreich 0.126046 0.174726 0.721 0.471
L1.Oberösterreich 0.220326 0.150202 1.467 0.142
L1.Salzburg 0.183206 0.079779 2.296 0.022
L1.Steiermark 0.097872 0.107928 0.907 0.364
L1.Tirol 0.154220 0.072274 2.134 0.033
L1.Vorarlberg 0.012518 0.068892 0.182 0.856
L1.Wien -0.117284 0.145048 -0.809 0.419
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.508543 0.184622 2.755 0.006
L1.Burgenland 0.016645 0.097150 0.171 0.864
L1.Kärnten 0.371217 0.078886 4.706 0.000
L1.Niederösterreich 0.097224 0.223511 0.435 0.664
L1.Oberösterreich -0.168462 0.192138 -0.877 0.381
L1.Salzburg 0.184484 0.102053 1.808 0.071
L1.Steiermark 0.252508 0.138062 1.829 0.067
L1.Tirol 0.139354 0.092453 1.507 0.132
L1.Vorarlberg 0.189193 0.088127 2.147 0.032
L1.Wien -0.577489 0.185546 -3.112 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303787 0.064504 4.710 0.000
L1.Burgenland 0.113770 0.033942 3.352 0.001
L1.Kärnten -0.024916 0.027561 -0.904 0.366
L1.Niederösterreich 0.044772 0.078091 0.573 0.566
L1.Oberösterreich 0.280504 0.067130 4.179 0.000
L1.Salzburg 0.003905 0.035656 0.110 0.913
L1.Steiermark -0.018057 0.048236 -0.374 0.708
L1.Tirol 0.094156 0.032301 2.915 0.004
L1.Vorarlberg 0.126777 0.030790 4.117 0.000
L1.Wien 0.081403 0.064826 1.256 0.209
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210671 0.075208 2.801 0.005
L1.Burgenland -0.005864 0.039575 -0.148 0.882
L1.Kärnten 0.024293 0.032135 0.756 0.450
L1.Niederösterreich 0.024937 0.091050 0.274 0.784
L1.Oberösterreich 0.384680 0.078270 4.915 0.000
L1.Salzburg 0.094704 0.041573 2.278 0.023
L1.Steiermark 0.186694 0.056241 3.320 0.001
L1.Tirol 0.043993 0.037662 1.168 0.243
L1.Vorarlberg 0.100743 0.035900 2.806 0.005
L1.Wien -0.067093 0.075585 -0.888 0.375
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.548695 0.149827 3.662 0.000
L1.Burgenland 0.074463 0.078840 0.944 0.345
L1.Kärnten 0.006203 0.064018 0.097 0.923
L1.Niederösterreich -0.032764 0.181386 -0.181 0.857
L1.Oberösterreich 0.131966 0.155927 0.846 0.397
L1.Salzburg 0.050766 0.082820 0.613 0.540
L1.Steiermark 0.124355 0.112042 1.110 0.267
L1.Tirol 0.222211 0.075028 2.962 0.003
L1.Vorarlberg 0.017012 0.071518 0.238 0.812
L1.Wien -0.129193 0.150577 -0.858 0.391
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150271 0.106874 1.406 0.160
L1.Burgenland -0.019283 0.056238 -0.343 0.732
L1.Kärnten -0.012054 0.045665 -0.264 0.792
L1.Niederösterreich 0.143567 0.129386 1.110 0.267
L1.Oberösterreich 0.382227 0.111226 3.437 0.001
L1.Salzburg -0.025964 0.059077 -0.440 0.660
L1.Steiermark -0.031690 0.079921 -0.397 0.692
L1.Tirol 0.188487 0.053519 3.522 0.000
L1.Vorarlberg 0.046109 0.051015 0.904 0.366
L1.Wien 0.184744 0.107409 1.720 0.085
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.227556 0.134539 1.691 0.091
L1.Burgenland 0.076460 0.070795 1.080 0.280
L1.Kärnten -0.050219 0.057486 -0.874 0.382
L1.Niederösterreich -0.060696 0.162878 -0.373 0.709
L1.Oberösterreich -0.099655 0.140016 -0.712 0.477
L1.Salzburg 0.031637 0.074369 0.425 0.671
L1.Steiermark 0.380288 0.100609 3.780 0.000
L1.Tirol 0.506227 0.067373 7.514 0.000
L1.Vorarlberg 0.192905 0.064220 3.004 0.003
L1.Wien -0.202542 0.135212 -1.498 0.134
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125854 0.156943 0.802 0.423
L1.Burgenland 0.017104 0.082585 0.207 0.836
L1.Kärnten -0.107400 0.067059 -1.602 0.109
L1.Niederösterreich 0.241177 0.190002 1.269 0.204
L1.Oberösterreich 0.025150 0.163333 0.154 0.878
L1.Salzburg 0.217758 0.086754 2.510 0.012
L1.Steiermark 0.122990 0.117364 1.048 0.295
L1.Tirol 0.098752 0.078592 1.257 0.209
L1.Vorarlberg 0.024980 0.074915 0.333 0.739
L1.Wien 0.243283 0.157729 1.542 0.123
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579563 0.085958 6.742 0.000
L1.Burgenland -0.020231 0.045232 -0.447 0.655
L1.Kärnten -0.001372 0.036728 -0.037 0.970
L1.Niederösterreich -0.041209 0.104064 -0.396 0.692
L1.Oberösterreich 0.281166 0.089458 3.143 0.002
L1.Salzburg 0.014596 0.047515 0.307 0.759
L1.Steiermark 0.014444 0.064280 0.225 0.822
L1.Tirol 0.073740 0.043045 1.713 0.087
L1.Vorarlberg 0.165649 0.041031 4.037 0.000
L1.Wien -0.062118 0.086388 -0.719 0.472
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.150672 -0.008173 0.214050 0.257785 0.067644 0.082947 -0.074310 0.157967
Kärnten 0.150672 1.000000 0.012120 0.194535 0.159662 -0.113388 0.164692 0.024963 0.313340
Niederösterreich -0.008173 0.012120 1.000000 0.289463 0.081220 0.228753 0.120385 0.060332 0.354326
Oberösterreich 0.214050 0.194535 0.289463 1.000000 0.293023 0.312514 0.087214 0.078162 0.124289
Salzburg 0.257785 0.159662 0.081220 0.293023 1.000000 0.161217 0.068834 0.072625 -0.015535
Steiermark 0.067644 -0.113388 0.228753 0.312514 0.161217 1.000000 0.112313 0.082329 -0.096094
Tirol 0.082947 0.164692 0.120385 0.087214 0.068834 0.112313 1.000000 0.147168 0.135834
Vorarlberg -0.074310 0.024963 0.060332 0.078162 0.072625 0.082329 0.147168 1.000000 0.085295
Wien 0.157967 0.313340 0.354326 0.124289 -0.015535 -0.096094 0.135834 0.085295 1.000000